package com.zmj.sy.mom.srv.aps.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zmj.sy.mom.srv.aps.bean.entity.mes.PartLog;
import com.zmj.sy.mom.srv.aps.bean.vo.base.BasePageResVo;
import com.zmj.sy.mom.srv.aps.bean.vo.partlog.PartLogListReqVo;
import com.zmj.sy.mom.srv.aps.bean.vo.partlog.PartLogListResVo;
import com.zmj.sy.mom.srv.aps.mapper.PartLogMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@RequiredArgsConstructor
@Service
public class PartLogService {

    private final PartLogMapper partLogMapper;

    public BasePageResVo<PartLogListResVo> list(PartLogListReqVo reqVo) {
        Page<PartLog> page = partLogMapper.lambdaQuery()
                .eq(reqVo.getPartType() != null, PartLog::getPartType, reqVo.getPartType())
                .like(StringUtils.hasText(reqVo.getPartId()), PartLog::getPartId, reqVo.getPartId())
                .eq(reqVo.getLoadType() != null, PartLog::getLoadType, reqVo.getLoadType())
                .eq(StringUtils.hasText(reqVo.getLoadId()), PartLog::getLoadId, reqVo.getLoadId())
                .like(StringUtils.hasText(reqVo.getStationCode()), PartLog::getStationCode, reqVo.getStationCode())
                .like(StringUtils.hasText(reqVo.getGroupCode()), PartLog::getGroupCode, reqVo.getGroupCode())
                .eq(StringUtils.hasText(reqVo.getUserCode()), PartLog::getUserCode, reqVo.getUserCode())
                .eq(StringUtils.hasText(reqVo.getPhaseCode()), PartLog::getPhaseCode, reqVo.getPhaseCode())
                .eq(StringUtils.hasText(reqVo.getNextPhaseCode()), PartLog::getNextPhaseCode, reqVo.getNextPhaseCode())
                .orderByDesc(PartLog::getCreateDateTime)
                .page(reqVo.toPage());
        return BasePageResVo.of(page, PartLogListResVo.class);
    }

}
